package com.hzqy.service.epg;

import com.hzqy.persistence.dao.epg.AcTicketNumDao;
import com.hzqy.web.vo.epg.AcTicketNumVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class AcTicketNumService {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private AcTicketNumDao acDao;
	public  Map<String,Object> selectAc(AcTicketNumVo as, int page, int rows){
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("f_at_password", as.getF_at_password());
        map.put("f_at_frequency", as.getF_at_frequency());
        map.put("f_at_voteNum", as.getF_at_voteNum());
        map.put("f_at_serverid", as.getF_at_serverid());
        map.put("f_at_cdate", as.getF_at_cdate());
        map.put("f_at_udate", as.getF_at_udate());
        Integer rowCount = acDao.selectAcCount(map);
        map.put("total", rowCount);
        if(rowCount>0 && page>0 && rows>0){
            map.put("firstResult", (page-1)*rows);
            map.put("maxResults", rows);
            List<AcTicketNumVo> list=acDao.selectAcByRequest(map);
            map.put("rows", list);
        }else{
            map.put("rows", new ArrayList<AcTicketNumVo>());
        }
        return map;
	}
    /**
     * 增加内容---单条入库都利用此方法
     * @param TicketNumVo
     * @return
     */
    public Map<String,Object> insertTicketNumService(AcTicketNumVo TicketNumVo) {
        Map<String,Object> resultMap = new HashMap<String,Object>();
        int flag = 0;
        if(TicketNumVo==null || TicketNumVo.getF_at_password()==null||TicketNumVo.getF_at_voteNum()==null) {
           //不满足基本数据条件
            flag = -1;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<AcTicketNumVo> AcTicketNumVos = acDao.selectByRequest(TicketNumVo);
        resultMap.put("f_at_password",TicketNumVo.getF_at_password());
        resultMap.put("f_at_voteNum",TicketNumVo.getF_at_voteNum());
        resultMap.put("f_at_frequency",TicketNumVo.getF_at_frequency());
        resultMap.put("f_at_openid",TicketNumVo.getF_at_openid());
        resultMap.put("f_at_serverid",TicketNumVo.getF_at_serverid());
        if(flag ==0&&AcTicketNumVos.size()==0) {//直接插入数据
            try {
                  acDao.insertTicket(TicketNumVo);
                resultMap.put("success", true);
                resultMap.put("result", "新增内容成功!");
            }
            catch (Exception e){
                resultMap.put("success", false);
                resultMap.put("result","新增内容失败!");
            }
        }else{//失败
            resultMap.put("success", false);
            resultMap.put("result","重复新增内容失败!");
        }
        return resultMap;
    }

}
